﻿using System;

namespace dPet.Domain.Models
{
	using Hangerd;
	using Hangerd.Entity;

	public class InventoryBatchDetail : EntityBase
	{
		#region Public Properties

		/// <summary>
		/// 商品ID
		/// </summary>
		public string ProductId { get; private set; }

		/// <summary>
		/// 商品条码
		/// </summary>
		public string ProductBarcode { get; private set; }

		/// <summary>
		/// 商品名称
		/// </summary>
		public string ProductName { get; private set; }

		/// <summary>
		/// 单位名称
		/// </summary>
		public string UnitName { get; private set; }

		/// <summary>
		/// 库存量
		/// </summary>
		public int Quantity { get; private set; }

		/// <summary>
		/// 过期时间
		/// </summary>
		public DateTime ExpiryTime { get; private set; }

		#endregion

		#region Constructors

		private InventoryBatchDetail() { }

		public InventoryBatchDetail(string productId, int quantity, DateTime expiryTime)
		{
			if (quantity <= 0)
			{
				throw new HangerdException("库存量须大于0");
			}

			if (expiryTime <= DateTime.Now)
			{
				throw new HangerdException("过期时间不可早于当前时间");
			}

			this.ProductId = productId;
		
			this.Quantity = quantity;
			this.ExpiryTime = expiryTime;
		}

		#endregion

		#region Public Methods

		/// <summary>
		/// 记录商品信息
		/// </summary>
		public void RecordProductDetail(Product product)
		{
			this.ProductBarcode = product.Barcode;
			this.ProductName = product.Name;
			this.UnitName = product.UnitName;
		}

		#endregion
	}
}
